# -*- coding: utf-8 -*-
from django.views.generic.simple import direct_to_template
from lr.work.models import Work, WorkRels
from lr.face.views import check_user
from django.shortcuts import render_to_response


def catalogue(request):
    """ Список произведений """
    if not check_user(request):
        return render_to_response('lock_account.html')
    
    works = Work.objects.filter(contest=None).exclude(status=u'draft').order_by('date')
    work_list = []
    for work in works:
        work_list.append(work)
    if request.user.is_authenticated():
        trustee = WorkRels.objects.filter(trustee__id=request.user.id, work__status=u'draft')
        for trust in trustee:
            work_list.append(trust.work)
    catalogue_data = {}
    catalogue_data['works'] = work_list
    return direct_to_template(request, 'catalogue/catalogue.html', catalogue_data)    
